/* 
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
$(".btn-gt").click(function () {
    var projectid = $(this).data("id");
    console.log(projectid);
    layer.confirm('是否提交？', {
        btn: ['确认', '取消'] //可以无限个按钮
    }, function (index, layero) {
        //按钮【按钮一】的回调
        var datastr = "cont=2&projectid=" + projectid;
        $.ajax({
            url: "/../../controller/inspection/authcontroller.php",
            type: "POST",
            data: datastr,
            success: function (e) {
                var result = eval("(" + e + ")");
                if (result.code == 0) {
                    $("#userlist"+projectid).css("display","none");
                    layer.msg('操作成功', {
                        time: 2000, //20s后自动关闭
                        btn: ['OK']
                    })
                } else {
                    layer.msg('操作失败,请刷新重试', {
                        time: 2000, //20s后自动关闭
                        btn: ['OK']
                    })
                }
            }
        });
    });
});
$(".btn-rb").click(function () {
    var projectid = $(this).data("id");
    console.log(projectid);
    layer.confirm('是否提交？', {
        btn: ['确认', '取消'] //可以无限个按钮
    }, function (index, layero) {
        //按钮【按钮一】的回调
        var datastr = "cont=3&projectid=" + projectid;
        console.log(datastr);
        $.ajax({
            url: "/../../controller/inspection/authcontroller.php",
            type: "POST",
            data: datastr,
            success: function (e) {
                var result = eval("(" + e + ")");
                if (result.code == 0) {
                    $("#userlist"+projectid).css("display","none");
                    layer.msg('操作成功', {
                        time: 2000, //20s后自动关闭
                        btn: ['OK']
                    })
                } else {
                    layer.msg('操作失败,请刷新重试', {
                        time: 2000, //20s后自动关闭
                        btn: ['OK']
                    })
                }
            }
        });
    });
});
function submitall(ids) {
    var datastr = "cont=5&ids=" + ids;
    $.ajax({
        type: "post",
        url: "/../../controller/inspection/authcontroller.php",
        data: datastr,
        success: function (e) {
            var result = eval("(" + e + ")");
            if (result.code == 0) {
                layer.msg('操作成功', {
                    time: 2000, //20s后自动关闭
                    btn: ['OK']
                },function(){
                    window.location.reload();
                });
            } else {
                layer.msg('操作失败,请刷新重试', {
                    time: 2000, //20s后自动关闭
                    btn: ['OK']
                });
            }
        }
    });
}
function rebackall(ids) {
    var datastr = "cont=6&ids=" + ids;
    $.ajax({
        type: "post",
        url: "/../../controller/inspection/authcontroller.php",
        data: datastr,
        success: function (e) {
            var result = eval("(" + e + ")");
            if (result.code == 0) {
                layer.msg('操作成功', {
                    time: 2000, //20s后自动关闭
                    btn: ['OK']
                },function(){
                    window.location.reload();
                });
            } else {
                layer.msg('操作失败,请刷新重试', {
                    time: 2000, //20s后自动关闭
                    btn: ['OK']
                });
            }
        }
    });
}

function getprojectinfo(id) {
    var datastr = "cont=20&id=" + id;
    $.ajax({
        type: "post",
        url: "/../../controller/inspection/projectcontroller.php",
        data: datastr,
        success: function (e) {
            var result = eval("(" + e + ")");
            if (result.code == 0) {
                resetpageex();
                $("#exname").html(result.data.exname);
                $("#exnation").html(result.data.nation);
                $("#spjdes").html(result.data.pjdes);
                $("#sex").html(result.data.sex);
                $("#age").html(result.data.age);
                $("#phone").html(result.data.phone);
                $("#dptment").html(result.data.department);
                $("#doctor").html(result.data.dptstaff);
                $("#hospitalnum").html(result.data.hospitalnum);
                $("#clinicalfind").html(result.data.clinicalfind);
                $("#exqq").html(result.data.qq);
                $("#visittime").html(result.data.visittime);
                $("#address").html(result.data.address);
                $("#samplediv").html(result.data.sampledom);
            }
        }
    });
}

function resetpageex() {
    $("#exname").html("");
    $("#exnation").html("");
    $("#spjdes").html("");
    $("#sex").html("");
    $("#age").html("");
    $("#phone").html("");
    $("#dptment").html("");
    $("#doctor").html("");
    $("#hospitalnum").html("");
    $("#clinicalfind").html("");
    $("#exqq").html("");
    $("#visittime").html("");
    $("#address").html("");
    $("#samplediv").empty();
}

$(".btn-sch").click(function () {
    var codenum = $(this).data("code");
    $("#dialogtitle").html(codenum);
    var id = $(this).data("id");
    getprojectinfo(id);
});

$(".btn-tp").click(function () {
    var pid = $(this).data("id");
    if (pid == undefined || pid == "") {
        layer.msg('操作失败,请刷新重试', {
            time: 2000, //20s后自动关闭
            btn: ['OK']
        });
    } else {
        $("#ModifyProid").val(pid);
    }
});

$("#submitModify").click(function () {
    var pid = $("#ModifyProid").val();
    var itypeid = $("#ModifyTypeid").val();
    var datastr = "cont=10&pid=" + pid + "&itypeid=" + itypeid;
    $.ajax({
        type: "post",
        url: "/../../controller/inspection/authcontroller.php",
        data: datastr,
        success: function (e) {
            var result = eval("(" + e + ")");
            if (result.code == 0) {
                $("#insptype" + subid).html(result.name);
                layer.msg('操作成功', {
                    time: 2000, //20s后自动关闭
                    btn: ['OK']
                });
                $("#close_modify_modal1").trigger("click");
            } else {
                layer.msg('操作失败,请刷新重试', {
                    time: 2000, //20s后自动关闭
                    btn: ['OK']
                });
            }
        }
    });
});
//条码
$(".btn-cd").click(function () {
    var cont = 11;
    var proid = $(this).data("id");

    $.ajax({
        type: "post",
        url: "/../../controller/inspection/authcontroller.php",
        data: {
            cont: cont,
            proid: proid,
        },
        dataType: "json",
        success: function (rtJson) {
            var result = eval("("+rtJson+")");
            if (result.code == 0) {
                $("#barcode_img").attr("src", result.data.barcode);
                $("#barcode_href").attr("href", result.data.barcode);
            }
        }
    });
});

